package com.typhoon.spring_boot_demo1.service;

import com.typhoon.spring_boot_demo1.dto.SearchResultDto;
import com.typhoon.spring_boot_demo1.request.Operator;

import java.util.List;

/**
 * 通用搜索抽象类
 *
 */
public abstract class AbstractSearch implements ISearch {

    @Override
    public List<SearchResultDto> search(String key, Operator operator) {
        if(isParameterIllegal(key,operator)) {
            return null;
        }

        return bizSearch(key,operator);
    }

    /**
     * 具体业务查询
     *
     * @param key
     * @param operator
     * @return
     */
    public abstract List<SearchResultDto> bizSearch(String key, Operator operator);

    /**
     * 检查入参是否非法
     *
     * @param key
     * @param operator
     * @return
     */
    protected boolean isParameterIllegal(String key, Operator operator) {
        if(null == key || key.isEmpty()) {
            return true;
        }
        if(null == operator) {
            return true;
        }
        return false;
    }
}
